﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BLL.Enums;
using Model;
using BLL;
using DevExpress.Xpo;

namespace POS.Framework
{
    public class InfoDown
    {
        public delegate void TransferInfoHandler(string msg);
        public event TransferInfoHandler OnTransferInfoHandler;

        List<NeedDownloadData> AutoDownloadDataList = new List<NeedDownloadData>();

        BrandBLL brandBLL = new BrandBLL();
        CategoryBLL categoryBLL = new CategoryBLL();
        ProductBLL productBLL = new ProductBLL();
        StoreBLL storeBLL = new StoreBLL();
        WarehouseBLL warehouseBLL = new WarehouseBLL();
        UserBLL userBLL = new UserBLL();
        ProviderBLL providerBLL = new ProviderBLL();
        ProviderContactBLL providerContactBLL = new ProviderContactBLL();
        DateTime updateDate;
        public InfoDown(string[] execute)
        {
            foreach (string exec in execute) 
            {
                switch (exec.ToLower()) 
                {
                    case "brand":
                        updateDate = brandBLL.MaxUpdateDate();
                        brandBLL.BatchInsert(updateDate);
                        break;
                    case "category":
                        updateDate=categoryBLL.MaxUpdateDate();
                        categoryBLL.BatchInsert(updateDate);
                        break;
                    case "product":
                        updateDate = productBLL.MaxUpdateDate();
                        productBLL.BatchInsert(updateDate);
                        break;
                    case "provider":
                        updateDate = providerBLL.MaxUpdateDate();
                        providerBLL.BatchInsert(updateDate);
                        break;
                    case "providercontact":
                        updateDate = providerContactBLL.MaxUpdateDate();
                        providerContactBLL.BatchInsert(updateDate);
                        break;
                }
            }
            //storeBLL.BatchInsert();
            //warehouseBLL.BatchInsert();
            //userBLL.BatchInsert();
            //providerBLL.BatchInsert();
            //providerContactBLL.BatchInsert();
        }
        public void Down()
        {
            this.OnTransferInfoHandler("正在下载资料...");
        }
    }
}
